package com.wjb.xietong.server.crm;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import com.wjb.xietong.datamanager.LoginUserDataManager;
import com.wjb.xietong.server.Msg;
import com.wjb.xietong.util.IDs;
import com.wjb.xietong.util.LogD;
import com.wjb.xietong.util.EnumDefine.Login_User_Info;

public class SellerStatis extends RequestBase{

	private SellerStatisInfo statisInfo;
	private long sellerID = 0;
	private String date = null;
	
	public SellerStatis(){
		msgType = Msg.TYPE_CRM_SELLER_STATIS;
	}

	
	public Msg requestSellerInfo(SellerStatisInfo statis, long slID, String dt){
		
		statisInfo = statis;
		sellerID = slID;
		date = dt;
		
		requsetInfo(IDs.CRM_URL);
		
		return getMsg();
	}
	
	@Override
	public Map<String, String> getRqstMap() {
		Map<String, String> map = new HashMap<String, String>();
		map.put(IDs.M, IDs.NOTIFY_CRM_STATIS);
		map.put(IDs.USER_ID, LoginUserDataManager.getLoginUserInfo(Login_User_Info.ID).toString());
		map.put(IDs.CRM_SELLER_ID, String.format("%d", sellerID));
		map.put(IDs.CRM_SELLER_DATE, date);
		return map;
	}

	@Override
	public int jsonGetResp(JSONObject resp){
		if (!checkRespCode(resp)) {
			// TODO
			return -1;
		}
		try {
			
			if(resp.has(IDs.CRM_PAID)){
				statisInfo.paid = resp.getDouble(IDs.CRM_PAID);
			}
			if(resp.has(IDs.CRM_WAIT_PAID)){
				statisInfo.waitToPay = resp.getDouble(IDs.CRM_WAIT_PAID);
			}
			if(resp.has(IDs.CRM_PAID_TRADE)){
				statisInfo.paidTrade = resp.getLong(IDs.CRM_PAID_TRADE);
			}
			if(resp.has(IDs.CRM_WAIT_PAID_TRADE)){
				statisInfo.waitToPaidTrade = resp.getLong(IDs.CRM_WAIT_PAID_TRADE);
			}
			if(resp.has(IDs.CRM_PAID_BUYER_NEW)){
				statisInfo.buyerNew = resp.getLong(IDs.CRM_PAID_BUYER_NEW);
			}
			if(resp.has(IDs.CRM_PAID_BUYER_OLD)){
				statisInfo.buyerOld = resp.getLong(IDs.CRM_PAID_BUYER_OLD);
			}
			if(resp.has(IDs.CRM_PAID_BUYER_ALL)){
				statisInfo.buyerAll = resp.getLong(IDs.CRM_PAID_BUYER_ALL);
			}
			

		} catch (JSONException e) {
			LogD.output("Exception:" + e.getMessage());
			return -2;
		}
		return 0;
	}
	
	@Override
	public void initData() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean parseJsonObj(JSONObject response) {
		// TODO Auto-generated method stub
		return false;
	}
	
	public static class SellerStatisInfo{
		public double paid;
		public double waitToPay;
		public long paidTrade;
		public long waitToPaidTrade;
		public long buyerNew;
		public long buyerOld;
		public long buyerAll;
		
		public SellerStatisInfo(){
			
		}
	}
}
